package zjh_20230310;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

public class practise03 {
    public static void main(String[] args) throws IOException {
        /*
        File file2 = new File("D:\\kaifamiao\\code\\untitled2\\bbb","\\dad.doc");
        file2.createNewFile();
        */
        File file = new File("bbb");
//        String s = file.getPath();
//        System.out.println(s);
        HashMap<String, Integer> hashMap = new HashMap<>();
        kind(file, hashMap);


        System.out.println(hashMap.keySet()+ "-->" + hashMap.values());

    }

    public static HashMap<String,Integer> kind(File file, HashMap<String, Integer> hashMap) {
        File[] list = file.listFiles();
        for (File file1 :list) {
            if (file1.isFile()) {
                String s = file1.getName();
                String s1 = s.substring(s.lastIndexOf(".") + 1);
//                System.out.println(s1);
                if (!hashMap.containsKey(s1)) {
                    hashMap.put(s1, 1);
                } else {
                    Integer o = hashMap.get(s1);
                    hashMap.put(s1, ++o);
                }
            }
        }
        return hashMap;
    }
}
